package LinkedListPackage2;

import LinkedListPackage.ListNode;

import java.util.List;

/**
 * @author Lzm
 * @version 1.0
 */
public class swapPairs_ {

  public ListNode swapPairs(ListNode head) {
   if (head == null || head.next == null){
     return head;
   }
   ListNode dummyHead = new ListNode();
   dummyHead.next = head;
   ListNode temp = dummyHead;
   // 每次循环都创建2个临时节点
   while(temp.next != null && temp.next.next != null){
     ListNode temp1 = temp.next;
     ListNode temp2 = temp.next.next;
     temp.next = temp2;
     temp1.next = temp2.next;
     temp2.next = temp1;
     temp = temp.next.next;
   }
   return dummyHead.next;
  }
}
